package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.CenterBean09;
import com.lwj.liwanjia.utils.BaseUtils;

import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by 001 on 2017/9/21.
 */

public class ShouZhiMingXiAdapter extends RecyclerView.Adapter<ShouZhiMingXiAdapter.ViewHolder> {

    private Context mContext;
    private List<CenterBean09.DataBean> mList;

    public ShouZhiMingXiAdapter(Context mContext, List<CenterBean09.DataBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public ShouZhiMingXiAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_shou_zhi_ming_xi, parent, false);

        ViewHolder holder = new ViewHolder(view);

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

//                Toast.makeText(mContext, "不要点我", Toast.LENGTH_SHORT).show();
            }
        });

        return holder;
    }

    @Override
    public void onBindViewHolder(ShouZhiMingXiAdapter.ViewHolder holder, int position) {

        CenterBean09.DataBean bean = mList.get(position);

        Glide.with(mContext).load(bean.getPartyUserHeadImage()).error(R.mipmap.headportrait).into(holder.circle_photo);
        holder.tv_money.setText(bean.getOneCardItemNum());
        if(!TextUtils.isEmpty(bean.getPartyUserNick())) {
            holder.tv_name.setText(bean.getPartyUserNick() + " " + bean.getOneCardItemTypeView());
        }else{
            holder.tv_name.setText(bean.getOneCardItemTypeView());
        }

        String time = bean.getOneCardItemTime();
        String timeSub = time.substring(0, time.length() - 3);
        String timeResult = BaseUtils.getString(timeSub);
        holder.tv_time.setText(timeResult);

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        View view;
        CircleImageView circle_photo;
        TextView tv_money;
        TextView tv_name;
        TextView tv_time;

        public ViewHolder(View itemView) {
            super(itemView);

            view = itemView;
            circle_photo = (CircleImageView) itemView.findViewById(R.id.circle_photo);
            tv_money = (TextView) itemView.findViewById(R.id.tv_money);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);
        }
    }
}
